//加载layui的模板
layui.use(['layer', 'form', 'element', 'table'], function() {
	var layer = layui.layer,
		form = layui.form,
		element = layui.element,
		table = layui.table,
		laypage = layui.laypage;

	var tab = parent.tab; //处理点击切换选项卡事件
	$('a').off('click').on('click', function() {
		//处理点击链接打开选项卡
		var _that = $(this),
			_data = {
				title: _that.data('title'),
				icon: _that.data('icon'),
				id: _that.data('id'),
				url: _that.data('url')
			};
		tab.tabAdd(_data);

	});

	setTimeout(function() {
		TopimgFn();
	}, 1000)

	var tableArray1 = new Array();
	//查询热销产品
	AjaxPostFn('api/bizrelatives/selecthot?page=1&pagesize=100', "{'adcode':'100000','sorting':'present_price','tosort':'desc','hotState':'1'}", function(jsonData) {
		if(jsonData.pageInfo.size != 0) {
			$.each(jsonData.pageInfo.list, function(idx, obj1) {
				var presentPrice = 0;
				if(obj1.bizCommodityForSalePrices[0]) {
					presentPrice = obj1.bizCommodityForSalePrices[0].presentPrice / 100; //价格
				}
				var obj = obj1.bizCommodityForSales;
				tableArray1.push({
					"id": obj.id,
					"commodityNumber": obj.commodityNumber,
					"commodityId": obj.commodityId,
					"shortName": obj.shortName,
					"title": obj.title,
					"smallTitle": obj.smallTitle,
					"listingDate": obj.listingDate,
					"offlineDate": obj.offlineDate,
					"presentPrice": presentPrice,
					"originalPrice": obj.originalPrice / 100,
					"shelfState": obj.shelfState,
					"saleUnit": obj.saleUnit,
					"hotState": obj.hotState,
					"commodityStar": obj.commodityStar,
					"describes": obj.describes,
					"giftBarCodes": obj.giftBarCodes,
					"withGiftIcon": obj.withGiftIcon,
					"withGiftPhotos": obj.withGiftPhotos,
					"introduceUrl": obj.introduceUrl,
					"watchFrequency": obj.watchFrequency,
					"recommendState": obj.recommendState,
					"createDate": obj.createDate,
					"createId": obj.createId,
					"updateDate": obj.updateDate,
					"salesVolume": obj.salesVolume,
					"updateId": obj.updateId,
					"catalogId": obj.catalogId,
					"merchantNumber": obj.merchantNumber,
					"barCode": obj.barCode,
					"exhibitionPhoto": obj.exhibitionPhoto,
					"mainPhoto": "<img src='" + IMGUrl + "" + obj.mainPhoto + "'  class='classifyimg' / >",
					"introduce": obj.introduce

				});
			})
		}
		//渲染表格数据
		table.render({
			elem: '#main1',
			cols: [
				[ //标题
					{
						type: 'numbers',
						fixed: 'left',
						title: '行号'
					}, {
						field: 'id',
						minWidth: '0%',
						width: '0%',
						type: 'space',
						style: 'display:none' //id列隐藏
					}, {
						field: 'commodityNumber',
						width: 300,
						title: '条码'
					}, {
						field: 'title',
						width: 250,
						title: '名称'
					}, {
						field: 'presentPrice',
						width: 100,
						title: '现价/元'
					}, {
						field: 'originalPrice',
						width: 100,
						title: '原价/元'
					}, {
						field: 'mainPhoto',
						width: 100,
						title: '主图'
					}, {
						field: 'merchantNumber',
						width: 100,
						title: '商户编号'
					}, {
						field: 'salesVolume',
						width: 100,
						title: '销量'
					}
				]
			],
			data: tableArray1,
			height: 'full-400',
			even: true,
			page: true, //是否显示分页
			done: function() {

			}

		})

	})

	var tableArray3 = new Array();
	//获取会员名单	
	AjaxPostFn("system/customer/user/select?page=1&pagesize=100", "{'startDate':'2017-11-01','endDate':'" + getnowtime() + "'}", function(data) {
		if(data.pageInfo.size != 0) {
			$("#viptotal").html(data.pageInfo.size); //会员数量的统计
			$.each(data.pageInfo.list, function(idx, obj) {
				if(obj.customerWechat != undefined) {
					var objWechat = obj.customerWechat;
					tableArray3.push({
						"openId": objWechat.openId,
						"nickName": objWechat.nickName,
						"headimgurl1": "<img src='" + objWechat.headimgurl + "'  class='classifyimg' / >",
						"province": objWechat.province
					});
				}
			});

		}

		//展示已知数据
		var tableIns = table.render({
			elem: '#main3',
			cols: [
				[ //标题栏
					{
						type: 'numbers',
						fixed: 'left',
						title: '行号'
					}, {
						field: 'id',
						minWidth: '0%',
						width: '0%',
						type: 'space',
						style: 'display:none'
					}, {
						field: 'openId',
						width: 300,
						title: 'openID'
					}, {
						field: 'nickName',
						width: 200,
						title: '用户名'
					}, {
						field: 'headimgurl1',
						width: 100,
						title: '头像'
					}, {
						field: 'province',
						width: 150,
						title: '省份'
					},
				]
			],
			data: tableArray3,
			height: 'full-400',
			even: true,
			page: true, //是否显示分页
			done: function() {
				//图片点击放大

			}
		});
	})

	//查询本月订单
	var tableArray4 = new Array();
	AjaxPostFn('system/orderinfo/selectbyday?page=1&pagesize=3', "{'startDate':'" + thisMouth01() + "','endDate':'" + getnowtime() + "'}", function(jsonData) {
		if(jsonData.Error) {
			if(jsonData.Error == 203) {
				layer.msg(jsonData.Error.message);
				window.top.location.href = "login.html";
			}
		} else

		if(jsonData.pageInfo.size != 0) {
			$.each(jsonData.pageInfo.list, function(idx, obj) {
				tableArray4.push({
					"orderNumber": obj.orderNumber,
					"orderId": obj.orderId,
					"userId": obj.userId,
					"openid": obj.openid,
					"orderAddress": obj.orderAddress,
					"orderAdcode": obj.orderAdcode,
					"contactName": obj.contactName,
					"contactPhone": obj.contactPhone,
					"contactTelephone": obj.contactTelephone,
					"shippingMethod": obj.shippingMethod,
					"orderState": obj.orderState,
					"paymentMethod": obj.paymentMethod,
					"paymentAmount": obj.paymentAmount,
					"paymentState": obj.paymentState,
					"expressNumber": obj.expressNumber,
					"expressBusiness": obj.expressBusiness,
					"orderRemarks": obj.orderRemarks,
					"generateTime": getMyDate(obj.generateTime),
					"invoiceType": obj.invoiceType,
					"invoiceHeader": obj.invoiceHeader,
					"deliveryNumber": obj.deliveryNumber,
					"orderMachineIp": obj.orderMachineIp,
					"deviceInfo": obj.deviceInfo,
					"tradeType": obj.tradeType,
					"transactionId": obj.transactionId,
					"paySuccessTime": obj.paySuccessTime,
					"orderType": obj.orderType,
					"scoreUse": obj.scoreUse,
					"orderProcess": obj.orderProcess,
					"orderPickupCode": obj.orderPickupCode,
					"merchantNumber": obj.merchantNumber,
					"evaluationState": obj.evaluationState,
				});
			})
		}

		table.render({
			elem: '#main4',
			cols: [
				[ //标题
					{
						type: 'numbers',
						fixed: 'left',
						title: '行号'
					}, {
						field: 'orderNumber',
						width: 180,
						title: '订单号'
					}, {
						field: 'orderAddress',
						width: 100,
						title: '订单地区'
					}, {
						field: 'contactName',
						width: 150,
						title: '收货人'
					}, {
						field: 'contactPhone',
						width: 100,
						title: '收货人手机'
					}, {
						field: 'contactTelephone',
						width: 180,
						title: '联系电话'
					}, {
						field: 'paymentAmount',
						width: 100,
						title: '金额'
					}, {
						field: 'orderRemarks',
						width: 100,
						title: '订单备注'
					}, {
						field: 'paymentMethod',
						width: 100,
						title: '付款方式'
					}, {
						field: 'paymentState',
						width: 100,
						title: '付款状态'
					}, {
						field: 'shippingMethod',
						width: 100,
						title: '装运方式'
					}, {
						field: 'expressNumber',
						width: 100,
						title: '快递单号'
					}, {
						field: 'expressBusiness',
						width: 100,
						title: '订单备注'
					}, {
						field: 'generateTime',
						width: 100,
						title: '生成时间'
					}, {
						field: 'invoiceType',
						width: 100,
						title: '发票类型'
					}, {
						field: 'invoiceHeader',
						width: 100,
						title: '发票抬头'
					}, {
						field: 'deliveryNumber',
						width: 100,
						title: '交货编码'
					}, {
						field: 'orderMachineIp',
						width: 100,
						title: '订单ip'
					}, {
						field: 'deviceInfo',
						width: 100,
						title: '设备信息'
					}, {
						field: 'tradeType',
						width: 100,
						title: '贸易类型'
					}, {
						field: 'transactionId',
						width: 100,
						title: '交易id'
					}, {
						field: 'orderType',
						width: 100,
						title: '订单类型'
					}, {
						field: 'scoreUse',
						width: 100,
						title: '积分使用'
					}, {
						field: 'orderProcess',
						width: 100,
						title: '订单审核'
					}, {
						field: 'orderPickupCode',
						width: 100,
						title: '订单拾取编码'
					}, {
						field: 'merchantNumber',
						width: 100,
						title: '店主编号'
					}, {
						field: 'evaluationState',
						width: 100,
						title: '评价状态'
					}, {
						field: 'wechatRefundResult',
						width: 100,
						title: '微信退款结果'
					}
				]
			],
			data: tableArray4,
			height: 'full-400',
			even: true,
			page: false, //是否显示分页
			done: function() {

			}

		})

	})

	//		今日订单数
	var nowtime0 = thisDay01(); //当天零点时间
	var nowtime = new Date().getTime(); //当前时间
	AjaxPostFn('system/orderinfo/selectbyday?page=1&pagesize=100', "{'startDate':" + nowtime0 + ",'endDate':" + nowtime + "}", function(jsonData) {
		$("#nowDayOrder").html(jsonData.pageInfo.total);
		if(jsonData.pageInfo.total != 0) {
			var Tprice = 0;
			$.each(jsonData.pageInfo.list, function(idx, obj) {
				if(obj.paymentAmount != null) {
					//			今日已付金额 = 今日成功交易的订单金额总和
					Tprice += obj.paymentAmount; //计算订单的价格
				}

			});

			$("#payprice").html("￥" + (Tprice / 100)); //今日订单的价格
		}
	})

	//		今日会员增加数
	AjaxPostFn("system/customer/user/select?page=1&pagesize=100", "{'startDate':'" + thisDay01() + "','endDate':'" + getnowtime() + "'}", function(data) {
		if(data.pageInfo.size != 0) {
			$("#todayVip").html(data.pageInfo.size);
		}
	});
});